<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script type="text/javascript">
	$("#version_datagrid_list").datagrid({
		url : '${ctx}/Wechat/datagrid.do',
		pagination : true,
		fit : true,
		border : true,
		idField : 'id',
		pageSize : 5,
		rownumbers : true,
		pageList : [ 5, 10, 20, 30, 50, 100 ],
		sortName : 'domainName',
		sortOrder : 'desc',
		checkOnSelect : true,
		selectOnCheck : true,
		columns : [ [ {
			field : 'id',
			hidden : true
		},{
			field : 'domainName',
			title : '域名'
		} ] ],
		toolbar : [  {
			text : '修改',
			iconCls : 'icon-edit',
			handler : function() {
				versionedit();
			}
		} ]
	});

	function versionedit(){
		var datagrid = $("#version_datagrid_list");
		var rows = datagrid.datagrid('getChecked');
		console.info(rows);
		var ids = "";
		if(rows.length == 0){
			$.messager.show({
				title:'提示',
				msg:'请您选择一条数据来做编辑操作！'
			});
		}
		if(rows.length > 1){
			$.messager.show({
				title:'提示',
				msg:'只能选择一条数据来做编辑操作！'
			});
		}
		if(rows.length == 1){
			var dynamic_dialog  = $("<div/>").dialog({
			    title: '域名信息修改',
			    width: 550,
			    height: 160,
			    closed: false,
			    cache: false,
			    href: '${ctx}/Wechat/versionedit.do',
			    modal: true,
			    buttons:[{
					text : '保存',
					iconCls: 'icon-add',
					handler : function() {
						$.serializeObject($('#versionEdit_edit_form'));
						$('#versionEdit_edit_form').form('submit',{
							url:'${ctx}/Wechat/editdomain.do',
							onSubmit:function(){
                                return $('#versionEdit_edit_form').form('validate')
							},
							success:function(data){
								var obj = $.parseJSON(data);
								if(obj.success){
									$('#version_datagrid_list').datagrid('load');//此方法还得发送一次查询的请求效率较低，所以要用下面的方法替代
									dynamic_dialog.dialog('close');
									datagrid.datagrid('updateRow',{
										index: datagrid.datagrid('getRowIndex',rows[0]),	// index start with 0,在第一行插入数据
										row: obj.obj
									});
								}
								$.messager.show({
									title:'提示',
									msg:obj.msg
								});
							}
						});
					}
				} ],
				onClose:function(){
					$(this).dialog('destroy');
				},
				onLoad:function(){
					$("#versionEdit_edit_form").form('load',rows[0]);
				}
			    
			});
		}
	}
</script>
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'center',border:false">
		<table id="version_datagrid_list"></table>
	</div>
</div>

